﻿using System;
using System.Collections.Generic;
using System.Text;

namespace unitlib
{
    public readonly struct Unit_kg : IUnit
    {
        public double Value { get; }
        public string Unit => "kg";

        public string LatexUnit => "\\mathrm{kg}";

        public Unit_kg(double value) { Value = value; }
        public Unit_kg Round(int digits) => new Unit_kg(Math.Round(Value, digits));
        //数值与字符串转换
        public override string ToString() => Value.ToString();
        public static explicit operator Unit_kg(double value) => new Unit_kg(value);
        public static explicit operator double(Unit_kg value) => value.Value;
        public static implicit operator Unit_kg(string value) => new Unit_kg(value.Parse());
        //比较运算
        public static bool operator ==(Unit_kg left, Unit_kg right) => left.Equals(right);
        public static bool operator !=(Unit_kg left, Unit_kg right) => !left.Equals(right);
        public override bool Equals(object obj) => obj is Unit_kg other && other.Value == Value;
        public override int GetHashCode()
        {
            unchecked
            {
                return GetType().GetHashCode() * 31 + Value.GetHashCode();
            }
        }
        //常规运算
        public static Unit_kg operator +(Unit_kg left, Unit_kg right) => new Unit_kg(left.Value + right.Value);
        public static Unit_kg operator -(Unit_kg left, Unit_kg right) => new Unit_kg(left.Value - right.Value);
        public static Unit_kg operator *(Unit_kg left, UnitValue right) => new Unit_kg(left.Value * right.Value);
        public static Unit_kg operator *(UnitValue left, Unit_kg right) => new Unit_kg(left.Value * right.Value);
        public static Unit_kg operator /(Unit_kg left, UnitValue right) => new Unit_kg(left.Value / right.Value);
        public static UnitValue operator /(Unit_kg left, Unit_kg right) => new UnitValue(left.Value / right.Value);
        //新增运算  
        public static Unit_kg_m operator /(Unit_kg left,Unit_m right) => new Unit_kg_m(left.Value / right.Value);
    }
}
